<template>
  <div>
    <!-- 抬头 -->
    <van-nav-bar :title="title" left-text="返回" left-arrow @click-left="goBack" />
    <!-- 扫码框 -->
    <div style="margin-top: 50px">
      <van-cell-group>
        <van-field v-model="code_input" ref="code_input" placeholder="请扫描条码" left-icon="scan"
          @input="onSubmitScanResult" />
          <br/>
          <van-button @click="onTurnProductList" 
          v-if="this.$route.query.key == 4"
          style="
        border: #3793fb solid 1px;
        border-radius: 2px;
        background-color: #3793fb;
        line-height: var(--footer-height);
      " type="primary" block>查看待确认清单</van-button>          
      </van-cell-group>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      code_input: "",
      title: "",
    };
  },
  mounted() {
    this.$refs.code_input.focus();
    this.title = this.$route.query.title;
  },
  methods: {
    // 返回按钮
    goBack() {
      this.$router.push("/HomePage");
    },
    //扫描提交
    onSubmitScanResult() {
      if (this.code_input !== "") {
        // if (this.code_input.includes(',')) {
          switch (this.$route.query.key) {
            case '1':
              this.$router.push({
                path: "/RawMaterialInfo",
                query: { rawMaterialInfo: this.code_input },
              });
              break;
            case '2':
              this.$router.push({
                path: "/MoveLocationInfo",
                query: { codeInfo: this.code_input },
              });
              break;
              case '3':
              this.$router.push({
                path: "/ProductionInbound",
                query: { codeInfo: this.code_input },
              });
              break;             
              case '4':
              this.$router.push({
                path: "/ProductInboundConfirm",
                query: { codeInfo: this.code_input },
              });
              break;
            case '5':
              this.$router.push({
                path: "/ProductOutbound",
                query: { codeInfo: this.code_input },
              });
              break;
            case '6':
              this.$router.push({
                path: "/SalesOutbound",
                query: { codeInfo: this.code_input },
              });
              break;
            default:
              break;
          }
        // } else {
        //   this.$toast.fail('条码信息错误');
        // }
      }
    },
    onTurnProductList(){
      this.$router.push({
                path: "/ProductInboundInfo",
                query: { codeInfo: this.code_input },
              });
    }
  },
};
</script>

<style></style>